# Remove Console Statements Script
Write-Host "Starting console cleanup..." -ForegroundColor Green

$extensions = @("*.js", "*.vue", "*.ts")
$searchPaths = @("src")
$totalFiles = 0
$modifiedFiles = 0
$removedLines = 0

foreach ($path in $searchPaths) {
    if (Test-Path $path) {
        $files = Get-ChildItem -Path $path -Include $extensions -Recurse | Where-Object {
            $_.FullName -notlike "*node_modules*" -and 
            $_.FullName -notlike "*uni_modules*"
        }
        
        foreach ($file in $files) {
            $totalFiles++
            $content = Get-Content $file.FullName -Encoding UTF8
            $modified = $false
            
            $newContent = @()
            foreach ($line in $content) {
                if ($line -match '^\s*console\.(log|error|warn|info|debug|trace)\s*\(.*\);\s*$') {
                    $modified = $true
                    $removedLines++
                    continue
                }
                elseif ($line -match '^\s*//\s*console\.(log|error|warn|info|debug|trace)') {
                    $modified = $true
                    $removedLines++
                    continue
                }
                else {
                    $originalLine = $line
                    $line = $line -replace '\s*console\.(log|error|warn|info|debug|trace)\s*\([^)]*\);\s*', ''
                    
                    if ($line -ne $originalLine) {
                        $modified = $true
                        $removedLines++
                    }
                    
                    if ($line -match '\S') {
                        $newContent += $line
                    }
                    elseif ($line -eq $originalLine) {
                        $newContent += $line
                    }
                }
            }
            
            if ($modified) {
                $modifiedFiles++
                $newContent | Out-File -FilePath $file.FullName -Encoding UTF8
                Write-Host "Processed: $($file.FullName)" -ForegroundColor Yellow
            }
        }
    }
}

Write-Host "Cleanup completed!" -ForegroundColor Green
Write-Host "Total files scanned: $totalFiles" -ForegroundColor Cyan
Write-Host "Modified files: $modifiedFiles" -ForegroundColor Cyan
Write-Host "Removed console statements: $removedLines" -ForegroundColor Cyan 